package com.xing.fragment;

import java.util.List;

import com.xing.adapter.SurveyListAdapter;
import com.xing.controller.DBController;
import com.xing.model.HsdModelSurvey;
import com.xing.questionnairesurvey.R;
import com.xing.util.CurrentUserUtil;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

public class SurveyListFragment extends SuperFragment{
	
	private ListView surveyListView;
	private View view;
	private FragmentManager fragmentManager; 
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		fragmentManager = getFragmentManager();
		return (view = inflater.inflate(R.layout.survey_fragment,container,false));
		
	}
	
	private Handler handler =  new Handler(){
		public void handleMessage(android.os.Message msg) {
			List<HsdModelSurvey> list = (List<HsdModelSurvey>) msg.obj;
			SurveyListAdapter adapter = new SurveyListAdapter(getActivity(), list,fragmentManager);
			surveyListView.setAdapter(adapter);
			adapter.notifyDataSetChanged();
			
		}
	};
	
	
	public void onHiddenChanged(boolean hidden) {
		if (!hidden) {
			DBController.getInstance().getHsdModelSurveyList(getActivity(), handler);
		}
	};
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		userNameTextView = (TextView) view.findViewById(R.id.user_name);
		userNameTextView.setText(CurrentUserUtil.userName+",欢迎使用!");
		surveyListView = (ListView) view.findViewById(R.id.survey_listview);
		DBController.getInstance().getHsdModelSurveyList(getActivity(), handler);
	}
	
}
